﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

/// <summary>
/// This class represents a Musician Object which contains information about the Musician's database entry.
/// </summary>
public class Musician
{
    /// <summary>
    /// Creates a Musician object based off of a unique Facebook Unique ID.
    /// </summary>
    /// <param name="uid">Facebook Unique ID.</param>
    /// <returns></returns>
    public static Musician CreateMusician(string uid)
    {
        string name = "";
        string picture = "";
        bool hasCV = false;
        bool hasWebsite = false;
        string website = "";

        // Connect to the database
        using (SqlConnection dbconn = new SqlConnection(Lutefisk.CONNECTION_STRING))
        {
            dbconn.Open();

            // Return the records of the user that has the specific unique id
            string searchString = "SELECT * FROM musicians WHERE uid = '" + uid + "' ;";
            
            using (SqlCommand sql = new SqlCommand(searchString, dbconn))
            {
                using (SqlDataReader reader = sql.ExecuteReader())
                {
                    // Read information about the user and store it in their respective fields
                    while (reader.Read())
                    {
                        name = reader["name"].ToString();
                        picture = reader["picture"].ToString();
                        hasCV = (int)reader["cv"] == (int)Lutefisk.CV.Valid ? true : false;
                        website = reader["website"].ToString();
                        hasWebsite = website != "" ? true : false;
                    }
                }
            }
        }

        return new Musician(name, picture, uid, hasCV, website, hasWebsite);
    }

    public Musician(string Name, string Picture, string UID, bool HasCV, string Website, bool HasWebsite)
    {
        this.Name = Name;
        this.Picture = Picture;
        this.UID = UID;
        this.HasCV = HasCV;
        this.Website = Website;
        this.HasWebsite = HasWebsite;
    }


    public bool HasWebsite
    {
        get;
        set;
    }

    public bool HasCV
    {
        get;
        set;
    }

    public string Website
    {
        get;
        set;
    }

    public string Name
    {
        get;
        set;
    }

    public string Picture
    {
        get;
        set;
    }

    public string UID
    {
        get;
        set;
    }

    public string CVLocation
    {
        get
        {
            return Lutefisk.WEBSITE_URL + "PDFs/" + UID + ".pdf";
        }
    }


}